<?php
require_once(dirname(__FILE__).'/../../WildPack/WildPack.php');
$wp = new WildPack();
$wp->using('util');
$wp->using('base');

class TestWpFilterer extends WpTestSuite
{
  
  /**
   * Preparation
   */
  public function prepare(){ return true; }
  
  /**
   * Test
   */
  public function test()
  {
    //-- striptag --
    $this->addMessage('Testing striptag');
    $this->addResult('Start and end tag (html)', 'text', WpFilterer::filter('striptag', '<html>text</html>'), '===');
    $this->addResult('Several single tags', 'texttext', WpFilterer::filter('striptag', 'text<br>text<br>'), '===');
    $this->addResult('Single tag with slash', 'text', WpFilterer::filter('striptag', 'text<br />'), '===');
    $this->addResult('Custom tag', 'text', WpFilterer::filter('striptag', '<my>text</my>'), '===');
    $this->addResult('No tags', 'text', WpFilterer::filter('striptag', 'text'), '===');
    $this->addResult('Single bigger as >', 'text', WpFilterer::filter('striptag', 'text > texty'), '===');
    $this->addResult('Single smaller as <', 'text', WpFilterer::filter('striptag', 'text < texty'), '===');
    $this->addResult('Single <=', 'text', WpFilterer::filter('striptag', 'text <= texty'), '===');
    $this->addResult('Single =>', 'text', WpFilterer::filter('striptag', 'text <= texty'), '===');
    
    //-- addslash --
    $this->addMessage('Testing addslash');
    $this->addResult('Single quote', "text\'text", WpFilterer::filter('addslash', "text'text"), '===');
    $this->addResult('Double quote', 'text\"text', WpFilterer::filter('addslash', 'text"text'), '===');
    $this->addResult('No quote', 'text', WpFilterer::filter('addslash', 'text'), '===');
    
    //-- blocktags --
    $this->addMessage('Testing block tags');
    $this->addResult('Start and end tag (html)', '&lthtml&gttext&lt/html&gt', WpFilterer::filter('blocktags', '<html>text</html>'), '===');
    $this->addResult('Several single tags', 'text&ltbr&gttext&ltbr&gt', WpFilterer::filter('blocktags', 'text<br>text<br>'), '===');
    $this->addResult('Single tag with slash', 'text&ltbr /&gt', WpFilterer::filter('blocktags', 'text<br />'), '===');
    $this->addResult('Custom tag', '&ltmy&gttext&lt/my&gt', WpFilterer::filter('blocktags', '<my>text</my>'), '===');
    $this->addResult('No tags', 'text', WpFilterer::filter('blocktags', 'text'), '===');
    $this->addResult('Single bigger as >', 'text &gt texty', WpFilterer::filter('blocktags', 'text > texty'), '===');
    $this->addResult('Single smaller as <', 'text &lt texty', WpFilterer::filter('blocktags', 'text < texty'), '===');
    $this->addResult('Single <=', 'text &lt= texty', WpFilterer::filter('blocktags', 'text <= texty'), '===');
    $this->addResult('Single =>', 'text &gt= texty', WpFilterer::filter('blocktags', 'text >= texty'), '===');
    
    //-- html2txt --
    $this->addMessage('Testing html2txt');
    $this->addResult('Start and end tag (html)', 'text', WpFilterer::filter('html2txt', '<html>text</html>'), '===');
    $this->addResult('Several single tags', 'texttext', WpFilterer::filter('html2txt', 'text<br>text<br>'), '===');
    $this->addResult('Single tag with slash', 'text', WpFilterer::filter('html2txt', 'text<br />'), '===');
    $this->addResult('Custom tag', 'text', WpFilterer::filter('html2txt', '<my>text</my>'), '===');
    $this->addResult('No tags', 'text', WpFilterer::filter('html2txt', 'text'), '===');
    $this->addResult('Single bigger as >', 'text', WpFilterer::filter('html2txt', 'text > texty'), '===');
    $this->addResult('Single smaller as <', 'text', WpFilterer::filter('html2txt', 'text < texty'), '===');
    $this->addResult('Single <=', 'text', WpFilterer::filter('html2txt', 'text <= texty'), '===');
    $this->addResult('Single =>', 'text', WpFilterer::filter('html2txt', 'text <= texty'), '===');
    
    //-- htmlspecialchars --
    $this->addMessage('Testing htmlspecialchars');
    $this->addResult('Umlauts', '&Auml;', WpFilterer::filter('htmlspecialchars', 'Ä'), '===');
    $this->addResult('Umlauts', '&Auml;tz', WpFilterer::filter('htmlspecialchars', 'Ätz'), '===');
    $this->addResult('Umlauts', '&auml;', WpFilterer::filter('htmlspecialchars', 'ä'), '===');
    $this->addResult('Umlauts', '&Ouml;', WpFilterer::filter('htmlspecialchars', 'Ö'), '===');
    $this->addResult('Umlauts', '&ouml;', WpFilterer::filter('htmlspecialchars', 'ö'), '===');
    $this->addResult('Umlauts', '&Uuml;', WpFilterer::filter('htmlspecialchars', 'Ü'), '===');
    $this->addResult('Umlauts', '&uuml;', WpFilterer::filter('htmlspecialchars', 'ü'), '===');
    $this->addResult('Umlauts', '&szlig;', WpFilterer::filter('htmlspecialchars', 'ß'), '===');
    $this->addResult('Special chars', '&amp;', WpFilterer::filter('htmlspecialchars', '&'), '===');
    $this->addResult('Special chars', '&lt;', WpFilterer::filter('htmlspecialchars', '<'), '===');
    $this->addResult('Special chars', '&gt;', WpFilterer::filter('htmlspecialchars', '>'), '===');
    $this->addResult('Special chars', '?', WpFilterer::filter('htmlspecialchars', '?'), '===');
    
    //-- htmlspecialchars_decode --
    $this->addMessage('Testing htmlspecialchars_decode');
    $this->addResult('Umlauts', 'Ä', WpFilterer::filter('htmlspecialchars_decode', '&Auml'), '===');
    $this->addResult('Umlauts', 'Ätz', WpFilterer::filter('htmlspecialchars_decode', '&Auml;tz'), '===');
    $this->addResult('Umlauts', 'ä', WpFilterer::filter('htmlspecialchars_decode', '&auml;'), '===');
    $this->addResult('Umlauts', 'Ö', WpFilterer::filter('htmlspecialchars_decode', '&Ouml;'), '===');
    $this->addResult('Umlauts', 'ö', WpFilterer::filter('htmlspecialchars_decode', '&ouml;'), '===');
    $this->addResult('Umlauts', 'Ü', WpFilterer::filter('htmlspecialchars_decode', '&Uuml;'), '===');
    $this->addResult('Umlauts', 'ü', WpFilterer::filter('htmlspecialchars_decode', '&uuml;'), '===');
    $this->addResult('Umlauts', 'ß', WpFilterer::filter('htmlspecialchars_decode', '&szlig;'), '===');
    $this->addResult('Special chars', '&', WpFilterer::filter('htmlspecialchars_decode', '&amp;'), '===');
    $this->addResult('Special chars', '<', WpFilterer::filter('htmlspecialchars_decode', '&lt;'), '===');
    $this->addResult('Special chars', '>', WpFilterer::filter('htmlspecialchars_decode', '&gt;'), '===');
    $this->addResult('Special chars', '?', WpFilterer::filter('htmlspecialchars_decode', '?'), '===');
    
    //-- htmlentities --
    $this->addMessage('Testing htmlentities');
    $this->addResult('Umlauts', '&Auml;', WpFilterer::filter('htmlentities', 'Ä'), '===');
    $this->addResult('Umlauts', '&Auml;tz', WpFilterer::filter('htmlentities', 'Ätz'), '===');
    $this->addResult('Umlauts', '&auml;', WpFilterer::filter('htmlentities', 'ä'), '===');
    $this->addResult('Umlauts', '&Ouml;', WpFilterer::filter('htmlentities', 'Ö'), '===');
    $this->addResult('Umlauts', '&ouml;', WpFilterer::filter('htmlentities', 'ö'), '===');
    $this->addResult('Umlauts', '&Uuml;', WpFilterer::filter('htmlentities', 'Ü'), '===');
    $this->addResult('Umlauts', '&uuml;', WpFilterer::filter('htmlentities', 'ü'), '===');
    $this->addResult('Umlauts', '&szlig;', WpFilterer::filter('htmlentities', 'ß'), '===');
    $this->addResult('Special chars', '&amp;', WpFilterer::filter('htmlentities', '&'), '===');
    $this->addResult('Special chars', '&lt;', WpFilterer::filter('htmlentities', '<'), '===');
    $this->addResult('Special chars', '&gt;', WpFilterer::filter('htmlentities', '>'), '===');
    $this->addResult('Special chars', '?', WpFilterer::filter('htmlentities', '?'), '===');
    
    //-- nl2br --
    $this->addMessage('Testing nl2br');
    $this->addResult('Single occurrence', "text<br />\ntext", WpFilterer::filter('nl2br', "text\ntext"), '===');
    $this->addResult('Twice occurrence', "text<br />\ntext<br />\ntext", WpFilterer::filter('nl2br', "text\ntext\ntext"), '===');
    $this->addResult('Beginning and end', "<br />\ntext<br />\n", WpFilterer::filter('nl2br', "\ntext\n"), '===');
    $this->addResult('Standalone', "<br />\n", WpFilterer::filter('nl2br', "\n"), '===');
    $this->addResult('No occurrence', "text", WpFilterer::filter('nl2br', "text"), '===');
    $this->addResult('br already there', "text<br><br />\ntext", WpFilterer::filter('nl2br', "text<br>\ntext"), '===');
    $this->addResult('br already there', "text<br /><br />\ntext", WpFilterer::filter('nl2br', "text<br />\ntext"), '===');
  }
  
  /**
   * Cleanup
   */
  public function cleanup(){}
  
  
}

$t = new TestWpFilterer();
$t->start('WpFilterer');
